package cn.wolfcode.crm.query;

import cn.wolfcode.crm.util.DateUtil;
import com.alibaba.druid.util.StringUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;


@Setter
@Getter
public class SalesReporQueryObject extends QueryObject{

    private Long companyId;
    private Long productId;

    @DateTimeFormat( pattern = "yyyy-MM-dd")
    private Date beginDate;
    @DateTimeFormat( pattern = "yyyy-MM-dd")
    private Date endDate;

    //设置默认按销售人员组
    private String groupByType="sm.username";

    //封住查询封装字段
    public String getGroupByType(){
        if (StringUtils.isEmpty(groupByType)) {
            return "sm.username";
        }
        return groupByType;
    }

    public Date getEndDate(){
        if (endDate!=null) {
            return DateUtil.getEndDate(endDate);
        }
        return null;
    }

    public static Map<String,String> groupSaleByTypes = new LinkedHashMap<>();
    //保单报表数据的封装报表
    static{
        groupSaleByTypes.put("sm.username", "销售人员");
        groupSaleByTypes.put("c.name", "保险机构");
        groupSaleByTypes.put("p.name", "保险产品");
        groupSaleByTypes.put("DATE_FORMAT(r.vdate,'%Y-%m')", "保单日期(月)");
        groupSaleByTypes.put("DATE_FORMAT(r.vdate,'%Y-%m-%d')", "保单日期(日)");
    }

}

